#include <stdio.h>
#include "sum_matrix.h"
#include "sum_TBB.h"
#include <Windows.h>

bool test( double* res1, double* res2, int w, int h)
{
	for( int i = 0; i < h; i++)
	{
		for( int j = 0; j < w; j++ )
		{
			if( res1[i*h + j] != res2[i*h + j])
				return false;
		}
	}

	return true;
}

int main()
{
	double *mtx1, *mtx2, *res, *resTBB;
	int w, h;

	w = h = 6000;

	mtx1 = new double [w * h];
	mtx2 = new double [w * h];

	for( int i = 0; i < h; i++)
	{
		for( int j = 0; j < w; j++ )
		{
			mtx1[i * h + j] = rand(); 
			mtx2[i * h + j] = rand();
		}
	}

	int start, finish1, finish2;

	start = GetTickCount();
	res = sum_Matrix( mtx1, mtx2, w, h );
	finish1 = GetTickCount();

	finish1 -= start;

	printf(" sum_Matrix time: %d\n",finish1);

	start = GetTickCount();
	task_scheduler_init init;

	resTBB = sum_TBB( mtx1, mtx2, w, h);
	finish2 = GetTickCount();

	finish2 -= start;

	printf(" sum_TBB: %d\n",finish2);
	/*
	if( finish1 != 0 )
	{
		printf(" Per sent (TBB/sum): %n.f\n", finish2/finish1);
	}*/

	printf(" Test : %s\n",  test(res, resTBB, w, h) ?  "OK" : "False");

	delete[] mtx1;
	delete[] mtx2;
	delete[] res;
	delete[] resTBB;

	return 0;
}